import db from '../utils/dbconf'
import { SQL_ERROR } from '../server.config.js'
const TABLE_NAME = 'PROJECT'


export default{
	workadd:async({id,plannum,status}) => {
		await db.execute(`
			UPDATE ${TABLE_NAME} 
			SET 
				PLANNUM = PLANNUM + ${plannum}
				${status?`,NOWNUM = NOWNUM + ${plannum}`:''}
			WHERE ID = ${id}
		`)
	},
  workcut:async({proid,num,status}) => {
		await db.execute(`
			UPDATE ${TABLE_NAME} 
			SET 
				PLANNUM = PLANNUM - ${num}
				${status?`,NOWNUM = NOWNUM - ${num}`:''}
			WHERE ID = ${proid}
		`)
	},
  over:async({id,num}) => {
    await db.table(TABLE_NAME)
    	.where({id})
    	.updateInc('nownum',num)
  },
  
  
  // verification:async (req,res,next) => {
  //   try{
  //     const { id:uid,type } = res.locals
  //     let pro_status
  //     if(type !== 99)
  //       pro_status =  await db.table(TABLE_NAME).where({uid,isok:-99}).field('uid,isok',true).select()
  //     else
  //       pro_status = await db.table(TABLE_NAME).where({uid}).page(1,10).select()
  //     return res.send({code:200,data:{pro_status}})
  //   }catch(e){
  //     console.log(e)
  //     return res.send(SQL_ERROR)
  //   }
  // },
  // figureout:async ({query:{proid,isok}},res,next) => {
  //   try{
  //     const { id:uid } = res.locals
  //     const num = await db.table(TABLE_NAME).where({uid,proid}).update({isok}).then(num=>num)
  //     if(num == 1)  return res.send({code:200})
  //     await db.table(TABLE_NAME).where({uid,proid}).update({isok:0})
  //     return res.send({code:500,msg:'ERROR:程序异常!!!'})
  //   }catch(e){
  //     return res.send(SQL_ERROR)
  //   }
  // }
}